// 组合优化
import { connect } from 'dva';
import React, { PureComponent } from 'react';

import 'moment/locale/zh-cn';
import SettingC from './mycomps/settingC';

import ResultIndexC from '../../../PortfolioManagement/portfolioOptimization/components/resultC';

@connect(({ optimizationM, loading }) => ({
  optimizationM,
  loading,
}))
export default class CombinatorialOptimization extends PureComponent {
  // eslint-disable-next-line react/state-in-constructor
  state = {
    pageStatus: '1', // 1参数设置 2结果页
    typeStatus: '1', // 1新增 2编辑 3 查看
    id: undefined, // 参数id
  };

  componentDidMount() {}

  changeStatus = (e, type) => {
    this.setState({
      pageStatus: e,
    });
    if (type) {
      this.setState({
        typeStatus: '1',
        id: undefined,
      });
    }
  };
  UNSAFE_componentWillReceiveProps(nextProps) {
    if (nextProps.productCode != this.props.productCode) {
      //组合切换后 页面切回初始化
      if(sessionStorage.getItem('queryFlag')){//如果是查看编辑 导致的组合代码变更，则不做处理
        sessionStorage.removeItem('queryFlag')
        return
      }
      this.changeStatus('1', '1');
    }
  }
 //获取组合code
 getCode = (id) => {
  const {
    workStationM: { productTableList = [] },
  } = this.props;
  let productObj = productTableList.filter((item) => item.portfolioId == id);
  return productObj[0]?.value;
};
  render() {
    const { productCode, portfolioType, portfolioId, changePortfolio } = this.props;
    const { pageStatus, typeStatus, id } = this.state;

    return (
      <div>
        {pageStatus == 1 && (
          <SettingC
            typeStatus={typeStatus}
            changeStatus={this.changeStatus}
            id={id}
            productCode={productCode}
            portfolioType={portfolioType}
            portfolioId={portfolioId}
            changePortfolio={changePortfolio}
          />
        )}
        {pageStatus == 2 && (
          <div>
            <ResultIndexC
              changeStatus={this.changeStatus}
              changeType={(e, type) => {
                console.log(e,'*****************')
                this.setState({
                  typeStatus: type,
                  id: e,
                });
              }}
              id={id}
              fromBarra={true}
              type='0'
            />
          </div>
        )}
      </div>
    );
  }
}
